package com.lysj.admin.cus.wxcustomer.feignImpl;

import com.lysj.admin.common.customer.feign.CustomerServiceFeign;
import com.lysj.admin.cus.wxcustomer.domain.WxCustomer;
import com.lysj.admin.cus.wxcustomer.service.WxCustomerService;
import com.lysj.admin.utils.web.ParamUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 14:14 2019/3/21
 * @ Description:
 **/
@RestController
public class CustomerServiceFeignImpl implements CustomerServiceFeign {

    @Resource
    private WxCustomerService wxCustomerService;


    @Override
    public Map<String, String> getOpenid() {
        Map<String, String> map = new HashMap<>();
        List<WxCustomer> wxCustomerList = wxCustomerService.findAll();
        for (WxCustomer wxCustomer : wxCustomerList) {
            map.put(wxCustomer.getId(), ParamUtil.isBlank(wxCustomer.getOpenId()) ? "" : wxCustomer.getOpenId());
        }
        return map;
    }

    @Override
    public String findByCustomerId(String customerId) {
        WxCustomer wxCustomer=wxCustomerService.findOne(customerId);
        if(ParamUtil.isBlank(wxCustomer)){
            return "";
        }
        return wxCustomer.getOpenId();
    }

    @Override
    public Map<String, String> phoneList() {
        Map<String, String> map = new HashMap<>();
        List<WxCustomer> wxCustomerList = wxCustomerService.findAll();
        for (WxCustomer wxCustomer : wxCustomerList) {
            map.put(wxCustomer.getId(), ParamUtil.isBlank(wxCustomer.getPhone()) ? "" : wxCustomer.getPhone());
        }
        return map;
    }
}
